<?php
/***************************************************************
*  Copyright notice
*  (c) 2009, jianyuzhu@gmail.com
*  All rights reserved
*  This script is part of the PPEMI project.
***************************************************************/

//
include_once(CONFIG_PATH . CONFIG_DIR_CLASSES . 'lib.json.class.php');

//
if( $action == 'getproducts' ) {
	include_once(CONFIG_PATH . CONFIG_DIR_CLASSES . 'module/product/product.class.php');
	$mObj = new ProductBase();
	$items = $mObj->getItems(array('keyword' => $keyword));
	$ds = array();
	for($i=0, $n=sizeof($items); $i<$n; $i++) {
		$ds[] = array('id' => $items[$i]['id'], 'name' => $items[$i]['name'], 'model' => $items[$i]['model']);
	}
	echo JsonUtil::encode($ds);
	exit();
} elseif( $action == 'getcontents' ) {
	include_once(CONFIG_PATH . CONFIG_DIR_CLASSES . 'module/content/content.class.php');
	$mObj = new ContentBase();
	$items = $mObj->getItems(array('keyword' => $keyword));
	$ds = array();
	for($i=0, $n=sizeof($items); $i<$n; $i++) {
		$ds[] = array('id' => $items[$i]['id'], 'name' => $items[$i]['subject'], 'link' => $items[$i]['link']);
	}
	echo JsonUtil::encode($ds);
	exit();
} elseif( $action == 'getvideos' ) {
	include_once(CONFIG_PATH . CONFIG_DIR_CLASSES . 'module/video/video.class.php');
	$mObj = new VideoBase();
	$items = $mObj->getItems(array('keyword' => $keyword));
	$ds = array();
	for($i=0, $n=sizeof($items); $i<$n; $i++) {
		$ds[] = array('id' => $items[$i]['id'], 'name' => $items[$i]['name'], 'link' => $items[$i]['link']);
	}
	echo JsonUtil::encode($ds);
	exit();
} elseif( $action == 'getresources' ) {
	include_once(CONFIG_PATH . CONFIG_DIR_CLASSES . 'module/resource/resource.class.php');
	$mObj = new ResourceBase();
	$items = $mObj->getItems(array('keyword' => $keyword));
	$ds = array();
	for($i=0, $n=sizeof($items); $i<$n; $i++) {
		$ds[] = array('id' => $items[$i]['id'], 'name' => $items[$i]['name'], 'link' => $items[$i]['link']);
	}
	echo JsonUtil::encode($ds);
	exit();
}
//
?>